#!/bin/bash
# 初始化元数据
function initialize_cluster_metadata(){
  cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/ || exit
  bin/pulsar initialize-cluster-metadata \
  --cluster pulsar-service-1 \
  --zookeeper 10.91.37.47:2181,10.91.37.48:2181,10.91.37.49:2181 \
  --configuration-store 10.91.37.47:2181,10.91.37.48:2181,10.91.37.49:2181 \
  --web-service-url http://10.91.37.47:8080,10.91.37.48:8080,10.91.37.49:8080 \
  --web-service-url-tls https://10.91.37.47:8443,10.91.37.48:8443,10.91.37.49:8443 \
  --broker-service-url pulsar://10.91.37.47:6650,10.91.37.48:6650,10.91.37.49:6650 \
  --broker-service-url-tls pulsar+ssl://10.91.37.47:6651,10.91.37.48:6651,10.91.37.49:6651
  # 接着初始化bookkeeper集群：若出现提示输入Y/N：请输入Y
  echo "Y" | bin/bookkeeper shell metaformat
}

# start bookie
function start_bookie(){
  cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/ || exit
  bin/pulsar-daemon start bookie
  echo "验证是否启动成功"
  echo "`bin/bookkeeper shell bookiesanity`"
}

# start broker
function start_broker(){
  cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/ || exit
  bin/pulsar-daemon start broker
  echo "验证是否启动成功"
  echo "`bin/pulsar-admin brokers list pulsar-service-1`"
}

# start pulsar-manager
function start_pulsar_manager(){
  cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/pulsar-manager/pulsar-manager || exit
  nohup bin/pulsar-manager > pulsar-manager.log 2>&1 &
  sleep 10s
  sh initAccount.sh
  echo -e "pulsar_manager平台访问链接: \c"
  info "https://10.91.37.48:7750/ui/index.html"
}

function pulsar_a(){
  initialize_cluster_metadata
  start_bookie
  start_broker
}

function pulsar_b(){
  start_bookie
  start_broker
  start_pulsar_manager
}

function pulsar_c(){
  start_bookie
  start_broker
}

# 如何使用
case $1 in
1)
  pulsar_a
;;
2)
  pulsar_b
;;
3)
  pulsar_c
;;
*)
echo "pulsar_a集群节点配置文件修改 $0 1(节点a)/2(节点b)/3(节点c)"
;;
esac
